package cn.lds.healthj377.dto;

import lombok.AllArgsConstructor;
import lombok.Data;

@Data
@AllArgsConstructor
public class ResponseDTO<T>{
	
	private Integer code;
	private String msg;
	private T data;
	
	public Integer getCode() {
		return code;
	}
	
	public String getMsg() {
		return msg;
	}
	
	public T getData() {
		return data;
	}
	
	/**
	 * 返回成功方法，不封装数据
	 * @return
	 */
	public static ResponseDTO buildSuccess(){
		return new ResponseDTO(ResultEnum.SUCCESS.getCode(),ResultEnum.SUCCESS.getMsg(), null);
	}
	
	/**
	 * 返回成功方法，封装返回的数据
	 * @param data
	 * @return
	 */
	public static ResponseDTO buildSuccess(Object data){
		return new ResponseDTO(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMsg(),data);
	}
	
	/**
	 * 返回成功方法，封装信息和返回数据
	 * @param data
	 * @param msg
	 * @return
	 */
	public static ResponseDTO buildSuccess(Object data, String msg){
		return new ResponseDTO(ResultEnum.SUCCESS.getCode(),msg,data);
	}
	
	/**
	 * 返回失败信息方法
	 * @return
	 */
	public static ResponseDTO buildError(){
		return new ResponseDTO(ResultEnum.ERROR.getCode(),ResultEnum.ERROR.getMsg(), null);
	}
	
	/**
	 * 返回失败信息方法，封装信息
	 * @param msg
	 * @return
	 */
	public static ResponseDTO buildError(String msg){
		return new ResponseDTO(ResultEnum.ERROR.getCode(),msg, null);
	}
	
	/**
	 * 返回失败信息方法，封装数据
	 * @param obj
	 * @return
	 */
	public static ResponseDTO buildError(Object obj){
		return new ResponseDTO(ResultEnum.ERROR.getCode(),ResultEnum.ERROR.getMsg(), obj);
	}
	
}